﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BLL;

namespace website.Menu
{
    /// <summary>
    /// GetMenuList 的摘要说明
    /// </summary>
    public class GetMenuList : IHttpHandler
    {
        string Action = "";
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            Action = RequstString("Action");
            //if (context.Request.Cookies["admininfo"] != null)
            //{

                string currentuser =  context.Request.Cookies["userno"].Value;
                if (Action == "GetUserMenu")
                {
                    context.Response.Write(GetUserMenu(currentuser));
                }
                //新增角色页面  当是宏大用户登录 构造权限树
                if (Action == "GetLimitTree")
                {
                    context.Response.Write(GetLimitTree());
                }
                //新增角色页面  当是客户登录 构造权限树
                if (Action == "initRoleLimitByCustomer")
                {

                    context.Response.Write(initRoleLimitByCustomer());
                }

            //}
        }

        public string GetUserMenu(string user)
        {
            string json = UserMenuBLL.GetMenuList(user);
            return json;
        }
        /// <summary>
        /// 新增角色页面  当是宏大用户登录 构造权限树
        /// </summary>
        /// <returns></returns>
        public string GetLimitTree()
        {
            string json = UserMenuBLL.GetLimitTree();
            return json;
        }
        /// <summary>
        /// 新增角色页面  当是客户登录 构造权限树
        /// </summary>
        /// <returns></returns>
        public string initRoleLimitByCustomer()
        {
            string CustomerName = RequstString("CustomerName");
            string json = UserMenuBLL.initRoleLimitByCustomer(CustomerName);
            return json;
        }


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        public static string RequstString(string sParam)
        {
            return (HttpContext.Current.Request[sParam] == null ? string.Empty
                  : HttpContext.Current.Request[sParam].ToString().Trim());
        }
    }
}